package com.jeecg.p3.system.poster.service;


import com.jeecg.p3.system.poster.dao.CustomerCouponDao;
import com.jeecg.p3.system.poster.entity.CustomerCoupon;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @ClassName: CustomerCouponService
 * @Description: TODO 顾客优惠券关联处理层
 * @author: zhangxiao
 * @date: 2020年11月30日 下午7:29:38
 */
@Service
public class CustomerCouponService {
    @Resource
    private CustomerCouponDao dao;

    /**
     * 分页查询顾客优惠券
     * @param pageQuery
     * @return
     */
    public PageList<CustomerCoupon> queryPageList(PageQuery<CustomerCoupon> pageQuery) {
        PageList<CustomerCoupon> result = new PageList<CustomerCoupon>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<CustomerCoupon> wrapper = new PageQueryWrapper<CustomerCoupon>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<CustomerCoupon> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取顾客优惠券数量
     * @param coupon
     * @return
     */
    public Integer count(CustomerCoupon coupon) {
        PageQuery<CustomerCoupon> pageQuery = new PageQuery<>();
        pageQuery.setQuery(coupon);
        return dao.count(pageQuery);
    }

    /**
     * 新增顾客优惠券信息
     * @param coupon
     */
    public void doAdd(CustomerCoupon coupon) {
        dao.insert(coupon);
    }

    /**
     * 根据id查询顾客优惠券信息
     * @param id
     * @return
     */
    public CustomerCoupon findById(Long id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取顾客优惠券列表信息
     * @param coupon
     * @return
     */
    public List<CustomerCoupon> findByParam(CustomerCoupon coupon) {
        return dao.findByParam(coupon);
    }

    /**
     * 编辑顾客优惠券信息
     * @param coupon
     */
    public void doEdit(CustomerCoupon coupon) {
        dao.update(coupon);
    }

    /**
     * 删除顾客优惠券信息
     * @param coupon
     */
    public void doDelete(CustomerCoupon coupon) {
        coupon.setStatus("0");
        dao.update(coupon);
    }
}
